package com.hxd.otc.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;

import com.hxd.otc.R;
import com.hxd.otc.widget.BlocksToast;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 包  名 :  com.hxd.wcb.client.widget
 * 类  名 :  DealBottomDialog
 * 作  者 :  zjl
 * 时  间 :  2018/6/7 16:49
 * 描  述 :  ${交易买卖底部Dialog}
 */
public class LoanDialog extends Dialog {
    @BindView(R.id.et_money_psw)
    EditText et_money_psw;
    @BindView(R.id.et_sms_code)
    EditText et_sms_code;
    @BindView(R.id.tv_send_message_code)
    TextView tv_send_message_code;

    public LoanDialog(Context context) {
        this(context, R.style.BlockDialog);

    }


    private LoanDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.dialog_loan);
        ButterKnife.bind(this);
        initWindows();

    }

    private void initWindows() {
        setCanceledOnTouchOutside(true);
        Window window = getWindow();
        if (window != null) {
            DisplayMetrics dm = new DisplayMetrics();
            window.getWindowManager().getDefaultDisplay().getMetrics(dm);
            WindowManager.LayoutParams windowAttributes = window.getAttributes();
            windowAttributes.width = WindowManager.LayoutParams.MATCH_PARENT;
            windowAttributes.height = WindowManager.LayoutParams.WRAP_CONTENT;
            window.setAttributes(windowAttributes);
        }
    }

    @OnClick({R.id.tv_cancel, R.id.tv_sure, R.id.tv_send_message_code})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_cancel:
                dismiss();
                break;
            case R.id.tv_sure:
                if (TextUtils.isEmpty(et_money_psw.getText().toString())) {
                    BlocksToast.get().showToast(getContext().getString(R.string.my_please_enter_the_money_password));
                    return;
                }
                if (TextUtils.isEmpty(et_sms_code.getText().toString())) {
                    BlocksToast.get().showToast(getContext().getString(R.string.phone_code_not_null));
                    return;
                }
                if (onItemClickListener != null) {
                    onItemClickListener.onSure();
                }
                dismiss();
                break;
            case R.id.tv_send_message_code:
                if (TextUtils.isEmpty(et_money_psw.getText().toString())) {
                    BlocksToast.get().showToast(getContext().getString(R.string.my_please_enter_the_money_password));
                    return;
                }
                if (onItemClickListener != null) {
                    onItemClickListener.sendCode();
                }
                break;
        }
    }

    @Override
    public void show() {
        super.show();
    }

    public TextView getTMmessage() {
        return tv_send_message_code;
    }

    public String getCode() {
        return et_sms_code.getText().toString();
    }

    public String getPsw() {
        return et_money_psw.getText().toString();
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    private OnItemClickListener onItemClickListener;

    public interface OnItemClickListener {
        void onSure();

        void sendCode();
    }
}
